#ifndef STALKMODEL_H
#define STALKMODEL_H

#include <QObject>

#include <QFile>
#include <QAudioInput>
#include <QAudioFormat>
#include <QAudioDeviceInfo>
#include <QTimer>
#include <QElapsedTimer>

#include "networkprotocol.h"
#include "networkpacket.h"

#include "audio/audiostreamencoder.h"
#include "audio/audiostreamdecoder.h"

#include "proto/contactlistresponsepacket.h"

class StalkModel : public QThread
{
    Q_OBJECT
public:
    static StalkModel *getInstance()
    {
        if(!StalkModel::__instance)
        {
            StalkModel::__instance = new StalkModel();
        }
        return StalkModel::__instance;
    }

    void auth(QString login, QString password);
    void setStatus(int statusId);

    void startVoiceBenchmark();

private:
    StalkModel();
    QElapsedTimer *timer = 0;
    void connectToServer();
    static StalkModel *__instance;
    NetworkProtocol *net = 0;

    QAudioInput *audioInput = 0;
    QFile outputFile;

    AudioStreamDecoder *audioStreamDecoder = 0;

    QString login;
    QString password;

private slots:
    void connected();
    void disconnected();
    void error();
    void gotPacket(NetworkPacket *packet);

public slots:
    void sendChunk(QByteArray data);
    void connectionFailed();

signals:
    void connectingSignal();
    void connectedSignal();
    void disconnectedSignal();

    void authSuccessSignal();
    void authFailedSignal();

    void contactsFullUpdate(QVariantMap);

    void errorSignal();
    void connectionFailedSignal();
};

#endif // STALKMODEL_H
